package com.lizk.study.netty.day009;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;

/**
 * ServerSocket服务端
 * @author lizhikui
 * @date 2019/6/30 11:29
 */
public class NioTest12_2 {
    public static void main(String[] args) throws IOException {
        Server server = new Server();
        server.startServer();

    }

    static class Server {
        public void startServer() throws IOException {
            ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
//            serverSocketChannel.configureBlocking(false);
            serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR,true);
            serverSocketChannel.bind(new InetSocketAddress(9999));
            while (true) {

                SocketChannel socketChannel = serverSocketChannel.accept();


                socketChannel.write(ByteBuffer.wrap("sdjfla".getBytes()));
                System.out.println("--------------------");
            }

        }
    }

}
